package com.jianxiu.bean;

import org.apache.commons.lang3.StringUtils;

import com.jianxiu.bean.task.Report;
import com.jianxiu.utils.NumUtils;

/**
 * 用户可操作信息
 */
public class OpView {

    public static final OpView FALSE = new OpView(false);

    private Long userId;
    private boolean opFlag;
    private String opName;
    private int opValue;

    public OpView(Long userId, String opName, int opValue, boolean opFlag) {
        this.userId = userId;
        this.opFlag = opFlag;
        this.opName = opName;
        this.opValue = opValue;
    }

    public OpView(Long userId, boolean opFlag) {
        this.userId = userId;
        this.opFlag = opFlag;
    }

    public OpView(boolean opFlag) {
        this.opFlag = opFlag;
    }

    public boolean isOpFlag() {
        return opFlag;
    }

    public String getOpName() {
        return opName;
    }

    public int getOpValue() {
        return opValue;
    }

    public Long getUserId() {
        return userId;
    }

    public void setOpFlag(boolean opFlag) {
        this.opFlag = opFlag;
    }

    public void setOpName(String opName) {
        this.opName = opName;
    }

    public void setOpValue(int opValue) {
        this.opValue = opValue;
    }

    public static OpView build(User user, Report report) {
        Long userId = user.getId();
          if (report.getStatus() == 1) {
            if (user.isWork() && NumUtils.eq(user.getId(), report.getMainId()))
                return new OpView(userId, "已办结", 2, true);
        } else if (report.getStatus() == 2) {
            if (user.isAdmin()) return new OpView(userId, "办结", 9, true);
        }
        return FALSE;
    }

    public boolean isEval() {
        return opValue == 8;
    }

    public static OpView buildOver(User user, Report report) {
        Long userId = user.getId();
        if (report.isOver() && NumUtils.eq(userId, report.getUserId()) && StringUtils.isBlank(report.getEvaluate())) {
            return new OpView(userId, "评价", 8, true);
        }
        return FALSE;
    }

    public static OpView buildInit(User user, Report report) {
        Long userId = user.getId();
        if (report.getStatus() == 0) {
            if (NumUtils.eq(user.getId(), report.getUserId())) return new OpView(userId, "删除", -1, true);
            if (user.isAdmin()) return new OpView(userId, "审核", 1, true);
        }
        return FALSE;
    }
}
